import os
import sys
import time
import atexit
import psutil  # 需要先安装: pip install psutil
import multiprocessing as mp
import subprocess

script_dir = os.path.dirname(os.path.abspath(__file__))

from NginxManger_2_0 import NginxManger

root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))



if __name__ == '__main__':
    # 获取当前脚本的目录
    nginx_path = os.path.join(os.path.dirname(__file__), 'nginx1272')
    NM = NginxManger(nginx_path=nginx_path)

    # -------------------------------------------------------------------------
    NM.Set_Listening({'listen_port': '9000',
                      'server_name': '127.0.0.1',})
    
    NM.Set_Mapping('http://127.0.0.1:9002', ['/employee'], os.path.join(root_dir, '02_employee', 'app.py'))
    NM.Set_Mapping('http://127.0.0.1:9004', ['/user_manager'], os.path.join(root_dir, '04_user_manager', 'app.py'))
    
    NM.Set_One_Server()

    # -------------------------------------------------------------------------
    NM.Save_Conf()
    NM.Run_nginx()


    # 定义路由和对应的脚本（如果有）
    # routes = [
    #     ('http://127.0.0.1:15002', ['/', '/auth'], os.path.join(root_dir, '02_Login', 'login.py')),
    #     ('http://127.0.0.1:15003', ['/dashboard'], os.path.join(root_dir, '03_Dashboard', 'dashboard.py')),
    #     ('http://127.0.0.1:15004', ['/notebook'], None),  # 不启动worker
    #     ('http://192.168.10.29:6020', ['/aiphoto'], None),
    #     ('http://127.0.0.1:15006', ['/contract'], None),
    #     ('http://127.0.0.1:15007', ['/view_20251021qweqwera'], None),
    #     ('http://127.0.0.1:15009', ['/salary_manager'], os.path.join(root_dir, '12_Salary_System', 'salary.py')),
    #     ('http://127.0.0.1:15010', ['/data_link'], os.path.join(root_dir, '10_Data_Link', 'datalink.py')),
    #     ('http://127.0.0.1:5001', ['/video'], None)
    # ]
